package com.etoak.controller;


import com.etoak.common.core.vo.PageVo;
import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.Dishes;
import com.etoak.entity.Ingredients;
import com.etoak.service.DishesService;
import com.etoak.vo.DishesVO;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author etoak
 * @since 2025-08-25
 */
@RestController
@RequestMapping("/dishes")
public class DishesController {

    @Autowired
    DishesService dishesService;

    /**
     * 添加接口 post /dishes
     *
     * @param dishes
     * @return
     */
    @PostMapping
    public ResultVO<Object> add(@Valid @RequestBody Dishes dishes) {
        dishesService.add(dishes);
        return ResultVO.success();
    }

    @GetMapping("/list")
    public ResultVO<Object> list(@RequestParam(required = false,defaultValue = "1") int pageNum,
                                       @RequestParam(required = false,defaultValue = "10") int pageSize,
                                       Dishes dishes) {
        PageVo<DishesVO> pageVo = dishesService.getList(pageNum,pageSize,dishes);
        return ResultVO.success(pageVo);

    }


    @PutMapping("/{id}")
    public ResultVO<Object> update(@PathVariable int id,@RequestBody Dishes dishes) {
        dishesService.updateDishes(id,dishes);
        return ResultVO.success();
    }

    @DeleteMapping("/{id}")
    public ResultVO<Object> delete(@PathVariable int id) {
        dishesService.delete(id);
        return ResultVO.success();
    }




}

